package com.googlecode.gxtmvp.rest.client;

public class Resource<D> {
  
  protected final String uri;
  
  public Resource(final String uri) {
    this.uri = uri;
  }
  
  public <O> CollectionResource<O> collection(final String step) {
    return uri.endsWith("/") ? new CollectionResource<O>(uri + step) : new CollectionResource<O>(uri + "/" + step);
  }
  
  public RestCommand<Void, Void> delete() {
    return new RestCommand<Void, Void>("DELETE", uri);
  }
  
  public <O> Resource<O> element(final String step) {
    return uri.endsWith("/") ? new Resource<O>(uri + step) : new Resource<O>(uri + "/" + step);
  }
  
  public <C> RestCommand<D, C> get(final Codec<String, C, D> codec, final C config) {
    return new RestCommand<D, C>("GET", uri, codec, config);
  }
  
  public String getUri() {
    return uri;
  }
  
  public <C> RestCommand<D, C> put(final D data, final Codec<String, C, D> codec, final C config) {
    return new RestCommand<D, C>("PUT", uri, data, codec, config);
  }
  
}
